<template>
  <view class="container">
    <view class="information" @click.stop="gotoInfo">
      <view class="headImg">
        <!-- <u-image height="240rpx" width="200rpx" radius="6" src="https://cdn.uviewui.com/uview/album/1.jpg"></u-image> -->
        <cloud-image :src="userInfo.avatar_file.url" width="200rpx" height="180rpx"></cloud-image>
      </view>
      <view class="" style="height: 100%;">
        <view class="infoBox">
          <view class="info-name-id">
            <view class="info-name">
              {{ userInfo.nickname || '未设置昵称'}}
            </view>
            <view class="info-id" @click.stop="copyId(userInfo.mobile)">
              phone：{{userInfo.mobile || '未绑定'}}
            </view>
          </view>
          <view class="">
            <u-icon name="arrow-right" size="18" bold></u-icon>
          </view>
        </view>
        <view class="collect-read">
          <view class="collect">
            <view class="">
              {{userInfo.integral}}
            </view>
            <view class="collect-txt">
              我的积分
            </view>
          </view>
          <view class="collect">
            <view class="">
              {{collection.length}}
            </view>
            <view class="collect-txt">
              我的收藏
            </view>
          </view>
          <view class="collect">
            <view class="">
              {{userInfo.viewCount || 0}}
            </view>
            <view class="collect-txt">
              阅读量
            </view>
          </view>
        </view>
      </view>
    </view>

    <view class="collect-box">
      <view class="collect-title" @click.stop="gotoCashList('collect')">
        <view class="">
          我的收藏
        </view>
        <u-icon name="arrow-right" bold></u-icon>
      </view>
      <view class="cashList">
        <view class="cashImage" v-for="data in collection" :key="data">
          <image class="" :src="data.avatar.url"></image>
        </view>
      </view>
    </view>

    <view class="collect-box">
      <view class="collect-box-1">
        <view class="collect-title" @click.stop="gotoCashList('fished')">
          <view class="">
            已完成记录
          </view>
          <u-icon name="arrow-right" bold></u-icon>
        </view>
        <view class="cashList">
          <view class="cashImage" v-for="data in finishList" :key="data">
            <image class="" :src="data.avatar.url"></image>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  import {
    mutations,
    store
  } from '@/uni_modules/uni-id-pages/common/store';
  export default {
    data() {
      return {
        collection: [],
        finishList: []
      };
    },
    computed: {
      userInfo() {
        return store.userInfo
      }
    },
    async onShow() {
      await this.init()
    },
    onPullDownRefresh() {
      console.log(111);
      this.init().then(async () => {
        console.log(222);
        uni.stopPullDownRefresh()
      })
    },
    methods: {
      init() {
        return new Promise(async (resolve) => {
          // COLLECTION
          let p1 = new Promise(async resolve => {
            let res = await uniCloud.callFunction({
              name: "getMyPageInfo",
              data: {
                flag: 1,
                userID: store.userInfo._id
              }
            })
            this.collection = res?.result?.data || []
            resolve()
          })
          //FINISHLIST
          let p2 = new Promise(async resolve2 => {
            let res2 = await uniCloud.callFunction({
              name: "getMyPageInfo",
              data: {
                flag: 2,
                userID: store.userInfo._id
              }
            })
            this.finishList = res2?.result?.data || []
            resolve2()
          })
          let p3 = mutations.updateUserInfo()
          await Promise.all([p1, p2, p3])
          resolve()
        })
      },
      copyId(id) {
        uni.setClipboardData({
          data: id,
          showToast: false,
          success: () => {
            uni.showToast({
              title: "电话复制成功",
              icon: 'none'
            })
          }
        })
      },
      gotoInfo() {
        uni.navigateTo({
          url: "/uni_modules/uni-id-pages/pages/userinfo/userinfo"
        })
      },
      gotoCashList(type) {
        uni.navigateTo({
          url: "/pages/cashList/cashList?type=" + type
        })
      }
    }
  }
</script>

<style lang="scss">
  .container {
    padding: 0 30rpx 0;
    background-color: #f0f0f0;
    min-height: 100vh;

    .information {
      display: flex;
      align-items: center;
      height: 214rpx;

      .infoBox {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: calc(100vw - 230rpx);
        height: 130rpx;
        padding: 0 30rpx;
        box-sizing: border-box;

        .info-name-id {

          .info-name {
            font-weight: bold;
            font-size: 38rpx;
          }

          .info-id {
            font-size: 26rpx;
            color: #5b5b5b;
            padding: 16rpx 0;
          }
        }
      }

      .collect-read {
        display: flex;
        align-items: center;
        justify-content: space-around;

        .collect {
          display: flex;
          flex-direction: column;
          align-items: center;
          font-weight: 600;
          font-size: 34rpx;

          .collect-txt {
            font-weight: 500;
            color: #434343;
            font-size: 28rpx;
          }
        }
      }
    }

    .collect-box {
      height: 250rpx;
      padding: 20rpx;
      margin-top: 40rpx;
      background-color: white;
      border-radius: 30rpx;


      .collect-title {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 10rpx;
      }

      .cashList {
        display: flex;
        overflow: hidden;

        .cashImage {
          height: 180rpx;
          flex: 0 0 23%;
          padding: 10rpx 18rpx 10rpx 0;

          image {
            height: 100%;
            width: 100%;
            border-radius: 10rpx;
          }
        }
      }
    }













  }
</style>